//----------------------------头文件依赖----------------------------//
#include "dev_lcd.h"
#include "dev_systick.h"

//----------------------------函数声明----------------------------//
static void lcd_bg_init(void);
static void lcd_specifications(LCD_InitStructure *);

static void RGB565__SWM34SRE_PIN64_A001(void);
static void RGB565__SWM34SVE_PIN100_A001(void);
static void RGB888__SWM34SVE_PIN100_A001(void);
static void RGB565__SWM34SVE_PIN100_A002(void);
static void RGB888__SWM34SVE_PIN100_A002(void);
static void RGB565__SWM34SVE_PIN100_USER1(void);

//----------------------------函数定义----------------------------//
void lcd_init(void)
{
	LCD_InitStructure LCD_initStruct;

	//复位
	GPIO_Init(LCD_GPIO_RST, LCD_PIN_RST, 1, 1, 0, 0);
	GPIO_AtomicSetBit(LCD_GPIO_RST, LCD_PIN_RST);
	swm_delay_ms(80);
	GPIO_AtomicClrBit(LCD_GPIO_RST, LCD_PIN_RST);
	swm_delay_ms(300); //复位时序请参考屏幕厂家提供的规格书描述进行
	GPIO_AtomicSetBit(LCD_GPIO_RST, LCD_PIN_RST);
	swm_delay_ms(120);
	//注意:若屏幕需要进行特定时序/参数的初始化（如SPI）,则应在 复位后~LCD_Start前 之间进行
	#if LCD_TYPE == RV_OTM8009A
	LCD_SPI_Init_OTM8009A();
  #endif
	
	// LCD 屏参适配------>若用户选择了自定义的屏, 仅该项需要根据不同的屏进行适配调整
	lcd_specifications(&LCD_initStruct);

	// LCD 硬件端口适配
#if (LCD_FMT == LCD_RGB565)

#if (SWM34S_LCM_PCBV == SWM34SRE_PIN64_A001)
	RGB565__SWM34SRE_PIN64_A001();
	
#elif (SWM34S_LCM_PCBV == SWM34SVE_PIN100_A001)
	RGB565__SWM34SVE_PIN100_A001();

#elif (SWM34S_LCM_PCBV == SWM34SVE_PIN100_A002)
	RGB565__SWM34SVE_PIN100_A002();
#elif (SWM34S_LCM_PCBV == SWM34SVE_PIN100_USER1)
	RGB565__SWM34SVE_PIN100_USER1();  
  
#endif //SWM34S_LCM_PCBV
	
#elif (LCD_FMT == LCD_RGB888)
	
#if (SWM34S_LCM_PCBV == SWM34SVE_PIN100_A001)
	RGB888__SWM34SVE_PIN100_A001();

#elif (SWM34S_LCM_PCBV == SWM34SVE_PIN100_A002)
	RGB888__SWM34SVE_PIN100_A002();
#endif //SWM34S_LCM_PCBV

#endif //LCD_FMT
	
	//以下其他设置_一般无须修改
	LCD_initStruct.Format = (LCD_FMT == LCD_FMT_RGB888) ? LCD_FMT_RGB888 : LCD_FMT_RGB565;
	LCD_initStruct.HnPixel = LCD_HDOT;
	LCD_initStruct.VnPixel = LCD_VDOT;
	//背景色
	LCD_initStruct.Background = (LCD_initStruct.Format == LCD_FMT_RGB888) ? 0xFFFFFF : 0xFFFF; 
	//图层 1 被 lvgl 使用, 此处仅做初始化临时值, 在 disp_flush() 会切换至 lcdbuf_gui/show 缓冲区 
	LCD_initStruct.DataSource = (uint32_t)SDRAMM_BASE;
	// 0-失能传输完成中断,刷完一帧自动开始刷新下一帧 		1-使能传输完成中断, 须在中断内启动刷新下一帧
	LCD_initStruct.IntEOTEn = 1;
	// 开启该中断可以给用户提供接口,以测试实际帧率
	LCD_Init(LCD, &LCD_initStruct);
	
	//背光
	lcd_bg_init();
}

//============================================================== 屏幕规格适配 ============================================================================//
static void lcd_specifications(LCD_InitStructure *LCD_initStruct)
{
	/*  一些屏参的计算参考示例, 实际请依据屏幕规格书为准
		HSYNC Blanking = 160 DCLK = HS Pulse Width + HS Back Porch
		HS Pulse Width = 1 ~ 140 DCLK
		1 Horizontal Line = 1344 DCLK 	(1200 ~ 1400)

		VSYNC Blanking = 23 H	  = VS Pulse Width + VS Back Porch
		VS Pulse Width = 1 ~ 20 H
		VSYNC period time = 635 H 		(624 ~ 750)
	*/
#if (LCD_HDOT == 480 && LCD_VDOT == 272) // 480*272

	//(JLT4303A)——晶力泰 4.3 寸电容屏
	LCD_initStruct->ClkDiv = 10;
	LCD_initStruct->Hfp = 5;
	LCD_initStruct->Hbp = 40;
	LCD_initStruct->Vfp = 8;
	LCD_initStruct->Vbp = 8;
	LCD_initStruct->HsyncWidth = 5;
	LCD_initStruct->VsyncWidth = 5;
	LCD_initStruct->SampleEdge = LCD_SAMPLE_FALL;

#elif (LCD_HDOT == 480 && LCD_VDOT == 480) // 480*480

#if (LCD_TYPE == TL040WVS03) //(TL040WVS03)——冠显光电 4.0 寸方形屏
#include "LCD_TL040WVS03.h"
	lcd_spi_init_TL040WVS03();

#elif (LCD_TYPE == TL021WVC02_Round) //(TL021WVC02_Round)——冠显光电 2.1 寸圆形屏
#include "LCD_TL021WVC02.h"
	lcd_spi_init_TL021WVC02();

#endif // LCD_TYPE

	LCD_initStruct->ClkDiv = 6;
	LCD_initStruct->Hfp = 10;
	LCD_initStruct->Hbp = 30;
	LCD_initStruct->Vfp = 20;
	LCD_initStruct->Vbp = 20;
	LCD_initStruct->HsyncWidth = 5;
	LCD_initStruct->VsyncWidth = 5;
	LCD_initStruct->SampleEdge = LCD_SAMPLE_RISE; //注意采样沿
	
#elif (LCD_HDOT == 480 && LCD_VDOT == 800) // 480*800

#if (LCD_TYPE == RV_HX8363A) //3.8 IPS
	LCD_initStruct->ClkDiv = 4;
	LCD_initStruct->Hfp = 64;
	LCD_initStruct->Hbp = 46;
	LCD_initStruct->Vfp = 22;
	LCD_initStruct->Vbp = 45;
	LCD_initStruct->HsyncWidth = 5;
	LCD_initStruct->VsyncWidth = 5;
	LCD_initStruct->SampleEdge = LCD_SAMPLE_RISE;

#elif (LCD_TYPE == RV_OTM8009A) //4.0

	LCD_initStruct->ClkDiv = 6;
	LCD_initStruct->Hfp = 20;
	LCD_initStruct->Hbp = 20;
	LCD_initStruct->Vfp = 16;
	LCD_initStruct->Vbp = 16;
	LCD_initStruct->HsyncWidth = 2;
	LCD_initStruct->VsyncWidth = 10;
	LCD_initStruct->SampleEdge = LCD_SAMPLE_RISE;

#endif // LCD_TYPE

#elif (LCD_HDOT == 800 && LCD_VDOT == 480) // 800*480

#if (LCD_TYPE == JLT4305A) //(JLT4305A)——晶力泰 4.3 寸电容屏
	LCD_initStruct->ClkDiv = 4;
	LCD_initStruct->Hfp = 64;
	LCD_initStruct->Hbp = 46;
	LCD_initStruct->Vfp = 22;
	LCD_initStruct->Vbp = 45;
	LCD_initStruct->HsyncWidth = 5;
	LCD_initStruct->VsyncWidth = 5;
	LCD_initStruct->SampleEdge = LCD_SAMPLE_FALL;

#elif (LCD_TYPE == ATK_MD0700R) //(ATK_MD0700R)——正点原子 7 寸电容屏

	/* STM32F429-LTCD ( TP-FT5206 驱动平替 TP-CST340 )
	lcdltdc.hsw=1;				    //水平同步宽度
	lcdltdc.vsw=1;				    //垂直同步宽度
	lcdltdc.hbp=46;				    //水平后廊
	lcdltdc.vbp=23;				    //垂直后廊
	lcdltdc.hfp=210;			    //水平前廊
	lcdltdc.vfp=22;				    //垂直前廊
	*/
	LCD_initStruct->ClkDiv = 4;
	LCD_initStruct->Hfp = 64;
	LCD_initStruct->Hbp = 46;
	LCD_initStruct->Vfp = 22;
	LCD_initStruct->Vbp = 23;
	LCD_initStruct->HsyncWidth = 5;
	LCD_initStruct->VsyncWidth = 5;
	LCD_initStruct->SampleEdge = LCD_SAMPLE_FALL;
  
#elif (LCD_TYPE == RV_OTM8009A) //4.0

	LCD_initStruct->ClkDiv = 6;
	LCD_initStruct->Hfp = 20;
	LCD_initStruct->Hbp = 20;
	LCD_initStruct->Vfp = 16;
	LCD_initStruct->Vbp = 16;
	LCD_initStruct->HsyncWidth = 2;
	LCD_initStruct->VsyncWidth = 10;
	LCD_initStruct->SampleEdge = LCD_SAMPLE_RISE;

#elif (LCD_TYPE == TYD070FR50NC)
	LCD_initStruct->ClkDiv = 4;
	LCD_initStruct->Hfp = 64;
	LCD_initStruct->Hbp = 46;
	LCD_initStruct->Vfp = 22;
	LCD_initStruct->Vbp = 23;
	LCD_initStruct->HsyncWidth = 5;
	LCD_initStruct->VsyncWidth = 5;
	LCD_initStruct->SampleEdge = LCD_SAMPLE_FALL;
  
#endif // LCD_TYPE

#elif (LCD_HDOT == 1024 && LCD_VDOT == 600) // 1024*600

#if (LCD_TYPE == WKS70170) // (WKS70170)——慧勤光电 7 寸电容屏
	LCD_initStruct->ClkDiv = 3; // type: 51.2 MHz
	LCD_initStruct->Hfp = 64;   // 16~216 type:160
	LCD_initStruct->Hbp = 140;
	LCD_initStruct->Vfp = 12; // 1~127 type:12
	LCD_initStruct->Vbp = 20;
	LCD_initStruct->HsyncWidth = 20;
	LCD_initStruct->VsyncWidth = 3;
	LCD_initStruct->SampleEdge = LCD_SAMPLE_FALL;

#elif (LCD_TYPE == H743) // (H743)——玫瑰科技 7 寸电容屏
	LCD_initStruct->ClkDiv = 3;		// type: 51.2 MHz
	LCD_initStruct->Hfp = 64;		// 64;//max:64
	LCD_initStruct->Hbp = 160;		// 140;//max:256
	LCD_initStruct->Vfp = 12;		// 12;//max:64
	LCD_initStruct->Vbp = 23;		// 12;//max:256
	LCD_initStruct->HsyncWidth = 20; // max:256
	LCD_initStruct->VsyncWidth = 3;	// max:256
	LCD_initStruct->SampleEdge = LCD_SAMPLE_FALL;

#endif // LCD_TYPE

#else // other custom

#error "You must provide your customized resolution Driver!"

#endif //(LCD_HDOT == ? && LCD_VDOT == ?)
}

//============================================================== PCB 硬件适配 ============================================================================//
static void lcd_bg_init(void)
{
#if (SWM34S_LCM_PCBV == SWM34SVE_PIN100_A001)
#define LCD_GPIO_BKL_EN 		GPIOA
#define LCD_PIN_BKL_EN 			PIN1
	//背光选通使能 <<仅针对 SWM34SVE_PIN100_A001 七寸屏背光电路(VGH/VGL)有效>>
	GPIO_Init(LCD_GPIO_BKL_EN, LCD_PIN_BKL_EN, 1, 1, 0, 0);
	GPIO_AtomicSetBit(LCD_GPIO_BKL_EN, LCD_PIN_BKL_EN); //选通 AP3012KTR-E1 芯片

#endif // SWM34S_LCM_PCBV == SWM34SVE_PIN100_A001

#if 1 //背光控制可选 IO 直驱 / PWN 调光
	GPIO_Init(LCD_GPIO_BL, LCD_PIN_BL, 1, 1, 0, 0);
	GPIO_AtomicSetBit(LCD_GPIO_BL, LCD_PIN_BL); //点亮背光

#else //背光 PWN 控制
	PORT_Init(LCD_PORT_BL, LCD_PIN_BL, LCD_PORT_FUNC_BL, 0);

	PWM_InitStructure PWM_initStruct;
	PWM_initStruct.Mode = PWM_CENTER_ALIGNED;
	PWM_initStruct.Clkdiv = 4;	   // F_PWM = 140M / 4 = 35M
	PWM_initStruct.Period = 10000; // 35M/10000 = 3500Hz，中心对称模式下频率降低到1750Hz

	PWM_initStruct.HdutyA = 2500;
	PWM_initStruct.DeadzoneA = 50;
	PWM_initStruct.IdleLevelA = 0;
	PWM_initStruct.IdleLevelAN = 0;
	PWM_initStruct.OutputInvA = 0;
	PWM_initStruct.OutputInvAN = 0;

	PWM_initStruct.HdutyB = 5000; // 5000/10000 = 50%
	PWM_initStruct.DeadzoneB = 50;
	PWM_initStruct.IdleLevelB = 0;
	PWM_initStruct.IdleLevelBN = 0;
	PWM_initStruct.OutputInvB = 0;
	PWM_initStruct.OutputInvBN = 0;

	PWM_initStruct.UpOvfIE = 0;
	PWM_initStruct.DownOvfIE = 0;
	PWM_initStruct.UpCmpAIE = 0;
	PWM_initStruct.DownCmpAIE = 0;
	PWM_initStruct.UpCmpBIE = 0;
	PWM_initStruct.DownCmpBIE = 0;
	PWM_Init(LCD_PORT_PWMN_BL, &PWM_initStruct);

	PWM_Start(LCD_PORT_PWMN_MSK_BL);
#endif
}

static void RGB565__SWM34SRE_PIN64_A001(void)
{
	// R- 5 bit : [ 3 ~ 7 ]
	PORT_Init(PORTC, PIN9, PORTC_PIN9_LCD_R3, 0);
	PORT_Init(PORTC, PIN10, PORTC_PIN10_LCD_R4, 0);
	PORT_Init(PORTC, PIN11, PORTC_PIN11_LCD_R5, 0);
	PORT_Init(PORTC, PIN12, PORTC_PIN12_LCD_R6, 0);
	PORT_Init(PORTC, PIN13, PORTC_PIN13_LCD_R7, 0);
	// G- 6 bit : [ 2 ~ 7 ]
	PORT_Init(PORTA, PIN14, PORTA_PIN14_LCD_G2, 0);
	PORT_Init(PORTA, PIN15, PORTA_PIN15_LCD_G3, 0);
	PORT_Init(PORTC, PIN0, PORTC_PIN0_LCD_G4, 0);
	PORT_Init(PORTC, PIN1, PORTC_PIN1_LCD_G5, 0);
	PORT_Init(PORTC, PIN2, PORTC_PIN2_LCD_G6, 0);
	PORT_Init(PORTC, PIN3, PORTC_PIN3_LCD_G7, 0);
	// B- 5 bit : [ 3 ~ 7 ]
	PORT_Init(PORTB, PIN15, PORTB_PIN15_LCD_B3, 0);
	PORT_Init(PORTA, PIN2, PORTA_PIN2_LCD_B4, 0);
	PORT_Init(PORTA, PIN9, PORTA_PIN9_LCD_B5, 0);
	PORT_Init(PORTA, PIN10, PORTA_PIN10_LCD_B6, 0);
	PORT_Init(PORTA, PIN11, PORTA_PIN11_LCD_B7, 0);

	// CLK / VS / HS / DE
	PORT_Init(PORTB, PIN5, PORTB_PIN5_LCD_DCLK, 0);
	PORT_Init(PORTB, PIN2, PORTB_PIN2_LCD_VSYNC, 0);

	PORT_Init(PORTB, PIN3, PORTB_PIN3_LCD_HSYNC, 0);
	PORT_Init(PORTB, PIN4, PORTB_PIN4_LCD_DEN, 0);
}

static void RGB565__SWM34SVE_PIN100_A001(void)
{
	//针对SWM34SVET6_Demo板上使用RGB565接口时多余IO未接地, 故程序中强制拉低, 用户也可做其他用途
	
	// R- 8 bit : [ 0 ~ 7 ]
	GPIO_Init(GPIOC, PIN4, 1, 0, 0, 0);
	GPIO_Init(GPIOC, PIN5, 1, 0, 0, 0);
	GPIO_Init(GPIOC, PIN8, 1, 0, 0, 0);
	GPIO_AtomicClrBit(GPIOC, PIN4);
	GPIO_AtomicClrBit(GPIOC, PIN5);
	GPIO_AtomicClrBit(GPIOC, PIN8);
	// R- 5 bit : [ 3 ~ 7 ]
	PORT_Init(PORTC, PIN9, PORTC_PIN9_LCD_R3, 0);
	PORT_Init(PORTC, PIN10, PORTC_PIN10_LCD_R4, 0);
	PORT_Init(PORTC, PIN11, PORTC_PIN11_LCD_R5, 0);
	PORT_Init(PORTC, PIN12, PORTC_PIN12_LCD_R6, 0);
	PORT_Init(PORTC, PIN13, PORTC_PIN13_LCD_R7, 0);
	
	// G- 8 bit : [ 0 ~ 7 ]
	GPIO_Init(GPIOA, PIN12, 1, 0, 0, 0);
	GPIO_Init(GPIOA, PIN13, 1, 0, 0, 0);
	GPIO_AtomicClrBit(GPIOA, PIN12);
	GPIO_AtomicClrBit(GPIOA, PIN13);
	// G- 6 bit : [ 2 ~ 7 ]
	PORT_Init(PORTA, PIN14, PORTA_PIN14_LCD_G2, 0);
	PORT_Init(PORTA, PIN15, PORTA_PIN15_LCD_G3, 0);
	PORT_Init(PORTC, PIN0, PORTC_PIN0_LCD_G4, 0);
	PORT_Init(PORTC, PIN1, PORTC_PIN1_LCD_G5, 0);
	PORT_Init(PORTC, PIN2, PORTC_PIN2_LCD_G6, 0);
	PORT_Init(PORTC, PIN3, PORTC_PIN3_LCD_G7, 0);
	
	// B- 8 bit : [ 0 ~ 7 ]
	GPIO_Init(GPIOB, PIN1, 1, 0, 0, 0);
	GPIO_Init(GPIOB, PIN11, 1, 0, 0, 0);
	GPIO_Init(GPIOB, PIN13, 1, 0, 0, 0);
	GPIO_AtomicClrBit(GPIOB, PIN1);
	GPIO_AtomicClrBit(GPIOB, PIN11);
	GPIO_AtomicClrBit(GPIOB, PIN13);
	// B- 5 bit : [ 3 ~ 7 ]
	PORT_Init(PORTB, PIN15, PORTB_PIN15_LCD_B3, 0);
	PORT_Init(PORTA, PIN2, PORTA_PIN2_LCD_B4, 0);
	PORT_Init(PORTA, PIN9, PORTA_PIN9_LCD_B5, 0);
	PORT_Init(PORTA, PIN10, PORTA_PIN10_LCD_B6, 0);
	PORT_Init(PORTA, PIN11, PORTA_PIN11_LCD_B7, 0);

	// CLK / VS / HS / DE
	PORT_Init(PORTB, PIN5, PORTB_PIN5_LCD_DCLK, 0);
	PORT_Init(PORTB, PIN2, PORTB_PIN2_LCD_VSYNC, 0);

	PORT_Init(PORTB, PIN3, PORTB_PIN3_LCD_HSYNC, 0);
	PORT_Init(PORTB, PIN4, PORTB_PIN4_LCD_DEN, 0);
}

static void RGB888__SWM34SVE_PIN100_A001(void)
{
	// R- 8 bit : [ 0 ~ 7 ]
	PORT_Init(PORTC, PIN4, PORTC_PIN4_LCD_R0, 0);
	PORT_Init(PORTC, PIN5, PORTC_PIN5_LCD_R1, 0);
	PORT_Init(PORTC, PIN8, PORTC_PIN8_LCD_R2, 0);
	PORT_Init(PORTC, PIN9, PORTC_PIN9_LCD_R3, 0);
	PORT_Init(PORTC, PIN10, PORTC_PIN10_LCD_R4, 0);
	PORT_Init(PORTC, PIN11, PORTC_PIN11_LCD_R5, 0);
	PORT_Init(PORTC, PIN12, PORTC_PIN12_LCD_R6, 0);
	PORT_Init(PORTC, PIN13, PORTC_PIN13_LCD_R7, 0);
	
	// G- 8 bit : [ 0 ~ 7 ]
	PORT_Init(PORTA, PIN12, PORTA_PIN12_LCD_G0, 0);
	PORT_Init(PORTA, PIN13, PORTA_PIN13_LCD_G1, 0);
	PORT_Init(PORTA, PIN14, PORTA_PIN14_LCD_G2, 0);
	PORT_Init(PORTA, PIN15, PORTA_PIN15_LCD_G3, 0);
	PORT_Init(PORTC, PIN0, PORTC_PIN0_LCD_G4, 0);
	PORT_Init(PORTC, PIN1, PORTC_PIN1_LCD_G5, 0);
	PORT_Init(PORTC, PIN2, PORTC_PIN2_LCD_G6, 0);
	PORT_Init(PORTC, PIN3, PORTC_PIN3_LCD_G7, 0);
	
	// B- 8 bit : [ 0 ~ 7 ]
	PORT_Init(PORTB, PIN1, PORTB_PIN1_LCD_B0, 0);
	PORT_Init(PORTB, PIN11, PORTB_PIN11_LCD_B1, 0);
	PORT_Init(PORTB, PIN13, PORTB_PIN13_LCD_B2, 0);
	PORT_Init(PORTB, PIN15, PORTB_PIN15_LCD_B3, 0);
	PORT_Init(PORTA, PIN2, PORTA_PIN2_LCD_B4, 0);
	PORT_Init(PORTA, PIN9, PORTA_PIN9_LCD_B5, 0);
	PORT_Init(PORTA, PIN10, PORTA_PIN10_LCD_B6, 0);
	PORT_Init(PORTA, PIN11, PORTA_PIN11_LCD_B7, 0);

	// CLK / VS / HS / DE
	PORT_Init(PORTB, PIN5, PORTB_PIN5_LCD_DCLK, 0);
	PORT_Init(PORTB, PIN2, PORTB_PIN2_LCD_VSYNC, 0);

	PORT_Init(PORTB, PIN3, PORTB_PIN3_LCD_HSYNC, 0);
	PORT_Init(PORTB, PIN4, PORTB_PIN4_LCD_DEN, 0);
}

static void RGB565__SWM34SVE_PIN100_A002(void)
{
	//针对SWM34SVET6_Demo板上使用RGB565接口时多余IO未接地, 故程序中强制拉低, 用户也可做其他用途
	
	// R- 8 bit : [ 0 ~ 7 ]
	GPIO_Init(GPIOC, PIN4, 1, 0, 0, 0);
	GPIO_Init(GPIOC, PIN5, 1, 0, 0, 0);
	GPIO_Init(GPIOC, PIN8, 1, 0, 0, 0);
	GPIO_AtomicClrBit(GPIOC, PIN4);
	GPIO_AtomicClrBit(GPIOC, PIN5);
	GPIO_AtomicClrBit(GPIOC, PIN8);
	// R- 5 bit : [ 3 ~ 7 ]
	PORT_Init(PORTC, PIN9, PORTC_PIN9_LCD_R3, 0);
	PORT_Init(PORTC, PIN10, PORTC_PIN10_LCD_R4, 0);
	PORT_Init(PORTC, PIN11, PORTC_PIN11_LCD_R5, 0);
	PORT_Init(PORTC, PIN12, PORTC_PIN12_LCD_R6, 0);
	PORT_Init(PORTC, PIN13, PORTC_PIN13_LCD_R7, 0);
	
	// G- 8 bit : [ 0 ~ 7 ]
	GPIO_Init(GPIOA, PIN12, 1, 0, 0, 0);
	GPIO_Init(GPIOA, PIN13, 1, 0, 0, 0);
	GPIO_AtomicClrBit(GPIOA, PIN12);
	GPIO_AtomicClrBit(GPIOA, PIN13);
	// G- 6 bit : [ 2 ~ 7 ]
	PORT_Init(PORTA, PIN14, PORTA_PIN14_LCD_G2, 0);
	PORT_Init(PORTA, PIN15, PORTA_PIN15_LCD_G3, 0);
	PORT_Init(PORTC, PIN0, PORTC_PIN0_LCD_G4, 0);
	PORT_Init(PORTC, PIN1, PORTC_PIN1_LCD_G5, 0);
	PORT_Init(PORTC, PIN2, PORTC_PIN2_LCD_G6, 0);
	PORT_Init(PORTC, PIN3, PORTC_PIN3_LCD_G7, 0);
	
	// B- 8 bit : [ 0 ~ 7 ]
	GPIO_Init(GPIOB, PIN1, 1, 0, 0, 0);
	GPIO_Init(GPIOB, PIN11, 1, 0, 0, 0);
	GPIO_Init(GPIOB, PIN13, 1, 0, 0, 0);
	GPIO_AtomicClrBit(GPIOB, PIN1);
	GPIO_AtomicClrBit(GPIOB, PIN11);
	GPIO_AtomicClrBit(GPIOB, PIN13);
	// B- 5 bit : [ 3 ~ 7 ]
	PORT_Init(PORTB, PIN15, PORTB_PIN15_LCD_B3, 0);
	PORT_Init(PORTA, PIN2, PORTA_PIN2_LCD_B4, 0);
	PORT_Init(PORTA, PIN9, PORTA_PIN9_LCD_B5, 0);
	PORT_Init(PORTA, PIN10, PORTA_PIN10_LCD_B6, 0);
	PORT_Init(PORTA, PIN11, PORTA_PIN11_LCD_B7, 0);

	// CLK / VS / HS / DE
	PORT_Init(PORTB, PIN5, PORTB_PIN5_LCD_DCLK, 0);
	PORT_Init(PORTB, PIN2, PORTB_PIN2_LCD_VSYNC, 0);

	PORT_Init(PORTM, PIN8, PORTM_PIN8_LCD_HSYNC, 0);
	PORT_Init(PORTM, PIN11, PORTM_PIN11_LCD_DEN, 0);
}

static void RGB888__SWM34SVE_PIN100_A002(void)
{
	// R- 8 bit : [ 0 ~ 7 ]
	PORT_Init(PORTC, PIN4, PORTC_PIN4_LCD_R0, 0);
	PORT_Init(PORTC, PIN5, PORTC_PIN5_LCD_R1, 0);
	PORT_Init(PORTC, PIN8, PORTC_PIN8_LCD_R2, 0);
	PORT_Init(PORTC, PIN9, PORTC_PIN9_LCD_R3, 0);
	PORT_Init(PORTC, PIN10, PORTC_PIN10_LCD_R4, 0);
	PORT_Init(PORTC, PIN11, PORTC_PIN11_LCD_R5, 0);
	PORT_Init(PORTC, PIN12, PORTC_PIN12_LCD_R6, 0);
	PORT_Init(PORTC, PIN13, PORTC_PIN13_LCD_R7, 0);
	
	// G- 8 bit : [ 0 ~ 7 ]
	PORT_Init(PORTA, PIN12, PORTA_PIN12_LCD_G0, 0);
	PORT_Init(PORTA, PIN13, PORTA_PIN13_LCD_G1, 0);
	PORT_Init(PORTA, PIN14, PORTA_PIN14_LCD_G2, 0);
	PORT_Init(PORTA, PIN15, PORTA_PIN15_LCD_G3, 0);
	PORT_Init(PORTC, PIN0, PORTC_PIN0_LCD_G4, 0);
	PORT_Init(PORTC, PIN1, PORTC_PIN1_LCD_G5, 0);
	PORT_Init(PORTC, PIN2, PORTC_PIN2_LCD_G6, 0);
	PORT_Init(PORTC, PIN3, PORTC_PIN3_LCD_G7, 0);
	
	// B- 8 bit : [ 0 ~ 7 ]
	PORT_Init(PORTB, PIN1, PORTB_PIN1_LCD_B0, 0);
	PORT_Init(PORTB, PIN11, PORTB_PIN11_LCD_B1, 0);
	PORT_Init(PORTB, PIN13, PORTB_PIN13_LCD_B2, 0);
	PORT_Init(PORTB, PIN15, PORTB_PIN15_LCD_B3, 0);
	PORT_Init(PORTA, PIN2, PORTA_PIN2_LCD_B4, 0);
	PORT_Init(PORTA, PIN9, PORTA_PIN9_LCD_B5, 0);
	PORT_Init(PORTA, PIN10, PORTA_PIN10_LCD_B6, 0);
	PORT_Init(PORTA, PIN11, PORTA_PIN11_LCD_B7, 0);

	// CLK / VS / HS / DE
	PORT_Init(PORTB, PIN5, PORTB_PIN5_LCD_DCLK, 0);
	PORT_Init(PORTB, PIN2, PORTB_PIN2_LCD_VSYNC, 0);

	PORT_Init(PORTM, PIN8, PORTM_PIN8_LCD_HSYNC, 0);
	PORT_Init(PORTM, PIN11, PORTM_PIN11_LCD_DEN, 0);
}

//from RGB888__SWM34SVE_PIN100_A002() fork
static void RGB565__SWM34SVE_PIN100_USER1(void)
{
	// R- 5 bit : [ 3 ~ 7 ]
	PORT_Init(PORTC, PIN9, PORTC_PIN9_LCD_R3, 0);
	PORT_Init(PORTC, PIN10, PORTC_PIN10_LCD_R4, 0);
	PORT_Init(PORTC, PIN11, PORTC_PIN11_LCD_R5, 0);
	PORT_Init(PORTC, PIN12, PORTC_PIN12_LCD_R6, 0);
	PORT_Init(PORTC, PIN13, PORTC_PIN13_LCD_R7, 0);
	
	// G- 6 bit : [ 2 ~ 7 ]
	PORT_Init(PORTA, PIN14, PORTA_PIN14_LCD_G2, 0);
	PORT_Init(PORTA, PIN15, PORTA_PIN15_LCD_G3, 0);
	PORT_Init(PORTC, PIN0, PORTC_PIN0_LCD_G4, 0);
	PORT_Init(PORTC, PIN1, PORTC_PIN1_LCD_G5, 0);
	PORT_Init(PORTC, PIN2, PORTC_PIN2_LCD_G6, 0);
	PORT_Init(PORTC, PIN3, PORTC_PIN3_LCD_G7, 0);
	
	// B- 5 bit : [ 3 ~ 7 ]
	PORT_Init(PORTA, PIN1, PORTA_PIN1_LCD_B3, 0);//diff
	PORT_Init(PORTA, PIN2, PORTA_PIN2_LCD_B4, 0);
	PORT_Init(PORTA, PIN9, PORTA_PIN9_LCD_B5, 0);
	PORT_Init(PORTA, PIN10, PORTA_PIN10_LCD_B6, 0);
	PORT_Init(PORTA, PIN11, PORTA_PIN11_LCD_B7, 0);

	// CLK / VS / HS / DE
	PORT_Init(PORTB, PIN5, PORTB_PIN5_LCD_DCLK, 0);
	PORT_Init(PORTB, PIN2, PORTB_PIN2_LCD_VSYNC, 0);

	PORT_Init(PORTB, PIN3, PORTB_PIN3_LCD_HSYNC, 0);//diff
	PORT_Init(PORTB, PIN4, PORTB_PIN4_LCD_DEN, 0);
}


